/**
 * 
 */
package com.p2p.front.dal.dao;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.p2p.base.dao.BaseMapper;
import com.p2p.front.dal.model.BankCard;

/**
 * @author ruiqi
 *
 */
public interface BankCardDao extends BaseMapper {

	@Update("replace p2p_bank_card(uid,card,name,bank,area,city,branch,code,status,isdef) values(#{uid},#{card},#{name},#{bank},#{area},#{city},#{branch},#{code},11,#{isdef})")
	int replaceAll(BankCard bankCard);

	@Select("update p2p_bank_card set status= -1 where uid =  #{uid} and card = #{card}")
	void deleteCard(BankCard bankCard);

	@Select("select * from p2p_bank_card where uid =  #{uid} and card = #{card} and status != -1")
	BankCard getByUserAndCard(@Param(value = "uid") String uid,
			@Param(value = "card") String card);

	@Select("select * from p2p_bank_card where uid =#{userId}  and status != -1")
	List<BankCard> listAllCardByUser(String userId);

	@Select("select count(1) from p2p_bank_card where uid =#{userId}  and status != -1")
	Integer countBankCard(String userId);

	/**
	 * 根据对象里的参数动态更新字段,方便重用
	 * 
	 * @param bankCard
	 * @return
	 */
	int updateDynamic(BankCard bankCard);

	@Select("select * from p2p_bank_card where uid = #{userId} and isdef = 1")
	BankCard getDefaultBankCardByUserId(String userId);
}
